package cn.tedu.ems.controller;


import cn.tedu.ems.mapper.LoginMapper;
import cn.tedu.ems.pojo.dto.UserParam;
import cn.tedu.ems.pojo.vo.TokenUserVO;
import cn.tedu.ems.pojo.vo.UserVO;
import cn.tedu.ems.service.LoginService;
import cn.tedu.response.ResponseResult;
import cn.tedu.response.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("v1/ems/")
@Api(tags = "登录接口")
public class LoginController {
    @Autowired
    LoginService loginService;
    @Autowired
    LoginMapper loginMapper;

    @ApiOperation("登录功能")
    @PostMapping("login")
    public ResponseResult login(@RequestBody UserParam userParam){
        TokenUserVO login = loginService.login(userParam);
        return ResponseResult.ok(login);
    }


    //用户退出,从redis中删除当前用户的token,根据当前用户的用户名
    @PostMapping("loginOut")
    public ResponseResult loginOut(String userId){
        loginService.loginOut(userId);
        return ResponseResult.ok(StatusCode.OPERATION_SUCCESS);
    }



}
